<?php
/**
 * Created by PhpStorm.
 * Code Monkey: wcz
 * Date: 2018/3/21
 * Time: 10:17
 * PHP is the best language in the world
 */
namespace App\Http\Controllers\Imessage;

use App\Common\Result;
use App\Http\Controllers\Controller;
use App\Service\Imessage\MessageService;
use Illuminate\Http\Request;

class MessageController extends Controller
{
    /**
     * 用户消息列表
     */
    public static function userMessageList(Request $request)
    {
        $uid = $request->uid;

        $list = MessageService::getMessageList($uid);

        Result::msg('0','success',$list);
    }

    /**
     * 获取单个用户的离线消息
     */
    public static function userOutMessageDeatil(Request $request)
    {
        $to_uid = $request->to_uid;
        $from_uid = $request->from_uid;

        $list = MessageService::getUserOutMessage($to_uid, $from_uid);

        Result::msg('0','success',$list);
    }

    /**
     * 去除离线消息
     */
    public static function changeOut(Request $request)
    {
        $uid = $request->to_uid;
        $from_uid = $request->from_uid;

        if(MessageService::changeOutMessageStatus($uid, $from_uid) === false)
            Result::msg('-46','error','删除离线消息失败');
        else
            Result::msg('0','success',[]);
    }
}